﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gwen;
using Gwen.Control;
using System.IO;
using BoneImp;
using GLImp;
using System.Drawing;

namespace BoneEditor
{
	class MenuBar : Gwen.Control.MenuStrip
	{
		static Skeleton skeleton;

		public MenuBar()
			: base(MainCanvas.GetCanvas())
		{
			//FILE
			Gwen.Control.MenuItem file = AddItem("File");
			file.Menu.AddItem("Open").SetAction(delegate(Base sender){
				OpenFileDialog ofd = new OpenFileDialog();
				ofd.ShowDialog();
				OpenFileDialog ofdjson = new OpenFileDialog();
				ofdjson.ShowDialog();


				skeleton = Skeleton.LoadFromSpine(ofdjson.FileName, ofd.FileName);

				skeleton.state.data.setMixByName("walk", "jump", 0.4f);
				skeleton.state.data.setMixByName("jump", "walk", 0.4f);
				skeleton.TimeScale = 1.0f;

				skeleton.FlipX = false;
				skeleton.FlipY = false;

				skeleton.X = 320;
				skeleton.Y = 420;

				skeleton.state.setAnimationByName("walk", true);

				Program.MainCamera = new Camera2D();
				Program.MainCamera.OnRender += new GraphicsManager.Renderer(MainCamera_OnRender);

				GraphicsManager.SetBackground(Color.Blue);
				GraphicsManager.SetResolution(800, 600);
				GraphicsManager.Start();
			});
		}

		static void MainCamera_OnRender()
		{
			GraphicsManager.DrawRectangle(0, 0, 5, 5, Color.Blue);
			if (skeleton.state.animation.name == "walk")
			{
				if (skeleton.state.time > 1)
					skeleton.state.setAnimationByName("jump", false);
			}
			else
			{
				if (skeleton.state.time > 1)
					skeleton.state.setAnimationByName("walk", true);
			}

			skeleton.update(1 / 60f);
			skeleton.draw();
		}
	}

}
